package com.yungu.swift.socket.communication.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * NettyRunner
 *
 * @author cuixiuyin
 * @date 2018/12/15
 */

@Component
@ConfigurationProperties(prefix = "netty")
public class NettyRunner {
    private static final Logger logger = LoggerFactory.getLogger(NettyRunner.class);

    private int port;

    public void run() {
        //在初始化容器的时候启动 netty...
        logger.info("context bootstrap,init netty server...");
        //在这里启动netty
        NettyServer bootstrap = NettyServer.getInstance();
        NettyServer.port = port;
        try {
            bootstrap.init();
        } catch (InterruptedException e) {
            logger.error("init netty err.", e);
        }
    }


    public void setPort(int port) {
        this.port = port;
    }
}
